{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAABECAYAAACmjMM7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAACPElEQVR4nO3ZMYoTUQDG8ZdNSAJZdr1FzmApeBl7QVAP4DE8glhoIWxn4RFi5xViwJhMMhaxy2ZB/F7eEn6/dhj4qvnPmxn0fV8A4H9dtR4AwGUQFAAiBAWACEEBIGJ06sJ8Pu/KITjL880B4JG7KaXsF4vFUT9OBqUcYjKYTsa31WY1tutaL6irG+1bT6jqerBpPaGa1W7WekJV3XrVekJV09mk9YRqtuuulBNftx4KynI6Gd++fvWiyqjH4PuXyz583T3/0XpCVXdP3reeUM3Tr59bT6jq27tnrSdU9ebjy9YTqvnw9lPZrrt7H57+oQAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkDEoO/7ey/M5/N9KWUwnYzPu+iMdl3rBXV1o33rCVVdDzatJ1Sz2s1aT6iqW69aT6hqOpu0nlDNdt2VUkq/WCyODiSjB+7bl1Ku1r83y1rDqGzXekBdPy/6gP2r9YCqhsNh6wlV/X3oXqqbcujDkZMnFAD4F5f8igfAGQkKABGCAkCEoAAQISgARPwB8K5NVoTYsCUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x72 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import math\n",
    "import matplotlib.ticker as ticker\n",
    "import statsmodels.formula.api as smf\n",
    "from pprint import pprint\n",
    "import re as re\n",
    "\n",
    "from statsmodels.regression.mixed_linear_model import MixedLMResults\n",
    "\n",
    "import scipy as sp\n",
    "#from scipy.stats import nanmean\n",
    "#from scipy.stats import nanstd\n",
    "import copy\n",
    "import scipy.stats as stats\n",
    "import string\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.cm as cm\n",
    "from pprint import pprint\n",
    "import seaborn as sns\n",
    "sns.set(style=\"white\", context=\"talk\")\n",
    "custom_palette = [ \"greyish\", \"dusty purple\", \"greenish\", \"amber\", \"windows blue\", \"black\",\"faded green\"]  \n",
    "                     #\"green blue\", \"dull green\", \"faded green\",  \n",
    "sns.set_palette(sns.xkcd_palette(custom_palette))\n",
    "current_palette = sns.color_palette()\n",
    "%matplotlib inline\n",
    "sns.palplot(current_palette)\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "round_data = pd.read_csv('./all_studies_round_data.csv')\n",
    "\n",
    "round_data['group'] = 1 #this is only for the crossed mixed effect model\n",
    "\n",
    "game_rounds = pd.read_csv('./all_studies_game_data.csv')\n",
    "#round_data = round_data[round_data.round_index > 3]\n",
    "#print(round_data.size)\n",
    "conditions = ['dynamic_full_feedback',\n",
    "              'dynamic',         \n",
    "              'dynamic_self_feedback',\n",
    "              'dynamic_no_feedback',\n",
    "              'static',\n",
    "              'solo_feedback',\n",
    "              'solo_no_feedback'\n",
    "             ]\n",
    "\n",
    "\n",
    "colors ={'dynamic_no_feedback':'#196FFF',\n",
    "         'dynamic_self_feedback':'#000000',\n",
    "         'dynamic_full_feedback':'#E89468',\n",
    "         'dynamic': '#81B200',\n",
    "         'static':'#9B59B6',\n",
    "         'solo_feedback': '#95A5A6',\n",
    "         'solo_no_feedback': '#95A5A6'\n",
    "        }\n",
    "\n",
    "\n",
    "linestyles ={'dynamic_no_feedback':'-.',\n",
    "         'dynamic_self_feedback':':',\n",
    "         'dynamic_full_feedback':'-',\n",
    "         'dynamic': '-',\n",
    "         'static':'--',\n",
    "         'solo_feedback': '-',\n",
    "         'solo_no_feedback': '-'\n",
    "        }\n",
    "\n",
    "markers ={'dynamic_no_feedback':'d',\n",
    "         'dynamic_self_feedback':'^',\n",
    "         'dynamic_full_feedback':'p',\n",
    "         'dynamic': 'o',\n",
    "         'static':'*',\n",
    "         'solo_feedback': 'H',\n",
    "         'solo_no_feedback': 'h'\n",
    "        }\n",
    "\n",
    "#markers = ['s','o','*']\n",
    "#linestyles = ['--','-',':','-.']\n",
    "tick_size = 25\n",
    "label_size = 35\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "studies = [1,2]\n",
    "#crossed model with no independent groups https://stackoverflow.com/questions/50052421/mixed-models-with-two-random-effects-statsmodels\n",
    "# this is used as a variance component for the individual level stuff\n",
    "vcf = {\"player_id\": \"0 + C(player_id)\", \"game_id\": \"0 + C(game_id)\"} \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Table S4: The improvement of the best individual"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "study 1 adapted periods improvement of the best individual -- based on revised\n",
      "dynamic reduced error by  -26.98795180722892\n",
      "static reduced error by  -22.30517965468974\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "       <td>Model:</td>       <td>MixedLM</td> <td>Dependent Variable:</td> <td>improvement</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <td>No. Observations:</td>  <td>2758</td>         <td>Method:</td>          <td>REML</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "     <td>No. Groups:</td>      <td>274</td>         <td>Scale:</td>          <td>0.0011</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Min. group size:</td>     <td>9</td>      <td>Log-Likelihood:</td>    <td>5428.1150</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Max. group size:</td>    <td>20</td>        <td>Converged:</td>          <td>Yes</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Mean group size:</td>   <td>10.1</td>            <td></td>                <td></td>      \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "                           <td></td>                            <th>Coef.</th> <th>Std.Err.</th>    <th>z</th>    <th>P>|z|</th> <th>[0.025</th> <th>0.975]</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>                                            <td>0.000</td>   <td>0.001</td>   <td>0.000</td>  <td>1.000</td> <td>-0.002</td>  <td>0.002</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_feedback'))[T.dynamic]</th> <td>-0.036</td>   <td>0.003</td>  <td>-11.721</td> <td>0.000</td> <td>-0.041</td> <td>-0.030</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_feedback'))[T.static]</th>  <td>-0.030</td>   <td>0.003</td>  <td>-9.115</td>  <td>0.000</td> <td>-0.036</td> <td>-0.023</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Group Var</th>                                            <td>0.000</td>   <td>0.000</td>     <td></td>       <td></td>       <td></td>       <td></td>   \n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary2.Summary'>\n",
       "\"\"\"\n",
       "                             Mixed Linear Model Regression Results\n",
       "===============================================================================================\n",
       "Model:                          MixedLM             Dependent Variable:             improvement\n",
       "No. Observations:               2758                Method:                         REML       \n",
       "No. Groups:                     274                 Scale:                          0.0011     \n",
       "Min. group size:                9                   Log-Likelihood:                 5428.1150  \n",
       "Max. group size:                20                  Converged:                      Yes        \n",
       "Mean group size:                10.1                                                           \n",
       "-----------------------------------------------------------------------------------------------\n",
       "                                                    Coef.  Std.Err.    z    P>|z| [0.025 0.975]\n",
       "-----------------------------------------------------------------------------------------------\n",
       "Intercept                                            0.000    0.001   0.000 1.000 -0.002  0.002\n",
       "C(condition, Treatment('solo_feedback'))[T.dynamic] -0.036    0.003 -11.721 0.000 -0.041 -0.030\n",
       "C(condition, Treatment('solo_feedback'))[T.static]  -0.030    0.003  -9.115 0.000 -0.036 -0.023\n",
       "Group Var                                            0.000    0.000                            \n",
       "===============================================================================================\n",
       "\n",
       "\"\"\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"study 1 adapted periods improvement of the best individual -- based on revised\")\n",
    "\n",
    "forumla = \"improvement ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = round_data[(round_data.study==1) & (round_data.improvement.notnull()) & (round_data.best_player_revised)\n",
    "                  &  (round_data.quarter.isin([2,4]))\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['player_id']).fit()\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic'].independent_error.mean() ) / data[data.condition == 'dynamic'].independent_error.mean()\n",
    "\n",
    "print(\"dynamic reduced error by \", reduced_error*100)\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_error.mean() - \n",
    "                 data[data.condition == 'static'].independent_error.mean() ) / data[data.condition == 'static'].independent_error.mean()\n",
    "\n",
    "print(\"static reduced error by \", reduced_error*100)\n",
    "\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "study overall improvement of the best individual -- based on Revised\n",
      "dynamic reduced error by  -20.781599837166755\n",
      "static reduced error by  -18.9530201342282\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "       <td>Model:</td>       <td>MixedLM</td> <td>Dependent Variable:</td> <td>improvement</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <td>No. Observations:</td>  <td>5513</td>         <td>Method:</td>          <td>REML</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "     <td>No. Groups:</td>      <td>274</td>         <td>Scale:</td>          <td>0.0011</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Min. group size:</td>    <td>18</td>      <td>Log-Likelihood:</td>   <td>10946.4957</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Max. group size:</td>    <td>40</td>        <td>Converged:</td>          <td>Yes</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Mean group size:</td>   <td>20.1</td>            <td></td>                <td></td>      \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "                           <td></td>                            <th>Coef.</th> <th>Std.Err.</th>    <th>z</th>    <th>P>|z|</th> <th>[0.025</th> <th>0.975]</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>                                           <td>-0.000</td>   <td>0.001</td>  <td>-0.000</td>  <td>1.000</td> <td>-0.001</td>  <td>0.001</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_feedback'))[T.dynamic]</th> <td>-0.027</td>   <td>0.002</td>  <td>-10.902</td> <td>0.000</td> <td>-0.032</td> <td>-0.022</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_feedback'))[T.static]</th>  <td>-0.022</td>   <td>0.003</td>  <td>-8.242</td>  <td>0.000</td> <td>-0.027</td> <td>-0.017</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Group Var</th>                                            <td>0.000</td>   <td>0.000</td>     <td></td>       <td></td>       <td></td>       <td></td>   \n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary2.Summary'>\n",
       "\"\"\"\n",
       "                             Mixed Linear Model Regression Results\n",
       "===============================================================================================\n",
       "Model:                          MixedLM             Dependent Variable:             improvement\n",
       "No. Observations:               5513                Method:                         REML       \n",
       "No. Groups:                     274                 Scale:                          0.0011     \n",
       "Min. group size:                18                  Log-Likelihood:                 10946.4957 \n",
       "Max. group size:                40                  Converged:                      Yes        \n",
       "Mean group size:                20.1                                                           \n",
       "-----------------------------------------------------------------------------------------------\n",
       "                                                    Coef.  Std.Err.    z    P>|z| [0.025 0.975]\n",
       "-----------------------------------------------------------------------------------------------\n",
       "Intercept                                           -0.000    0.001  -0.000 1.000 -0.001  0.001\n",
       "C(condition, Treatment('solo_feedback'))[T.dynamic] -0.027    0.002 -10.902 0.000 -0.032 -0.022\n",
       "C(condition, Treatment('solo_feedback'))[T.static]  -0.022    0.003  -8.242 0.000 -0.027 -0.017\n",
       "Group Var                                            0.000    0.000                            \n",
       "===============================================================================================\n",
       "\n",
       "\"\"\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"study overall improvement of the best individual -- based on Revised\")\n",
    "\n",
    "forumla = \"improvement ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = round_data[(round_data.study==1) & (round_data.improvement.notnull()) & (round_data.best_player_revised)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['player_id']).fit(method='powell')\n",
    "\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic'].independent_error.mean() ) / data[data.condition == 'dynamic'].independent_error.mean()\n",
    "\n",
    "print(\"dynamic reduced error by \", reduced_error*100)\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_error.mean() - \n",
    "                 data[data.condition == 'static'].independent_error.mean() ) / data[data.condition == 'static'].independent_error.mean()\n",
    "\n",
    "print(\"static reduced error by \", reduced_error*100)\n",
    "\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "study 2 overall improvement of the best individual -- revised\n",
      "dynamic_no_feedback reduced error by  -14.965312190287452\n",
      "dynamic_self_feedback reduced error by  -21.098339719029404\n",
      "dynamic_full_feedback reduced error by  -30.473837862115488\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "       <td>Model:</td>       <td>MixedLM</td> <td>Dependent Variable:</td> <td>improvement</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <td>No. Observations:</td>  <td>1439</td>         <td>Method:</td>          <td>REML</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "     <td>No. Groups:</td>      <td>72</td>          <td>Scale:</td>          <td>0.0097</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Min. group size:</td>    <td>19</td>      <td>Log-Likelihood:</td>    <td>1247.8321</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Max. group size:</td>    <td>20</td>        <td>Converged:</td>          <td>Yes</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Mean group size:</td>   <td>20.0</td>            <td></td>                <td></td>      \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "                                    <td></td>                                    <th>Coef.</th> <th>Std.Err.</th>    <th>z</th>   <th>P>|z|</th> <th>[0.025</th> <th>0.975]</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>                                                            <td>-0.000</td>   <td>0.006</td>  <td>-0.000</td> <td>1.000</td> <td>-0.012</td>  <td>0.012</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_no_feedback'))[T.dynamic_full_feedback]</th> <td>-0.045</td>   <td>0.011</td>  <td>-4.268</td> <td>0.000</td> <td>-0.066</td> <td>-0.024</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_no_feedback'))[T.dynamic_no_feedback]</th>   <td>-0.020</td>   <td>0.011</td>  <td>-1.904</td> <td>0.057</td> <td>-0.041</td>  <td>0.001</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_no_feedback'))[T.dynamic_self_feedback]</th> <td>-0.028</td>   <td>0.011</td>  <td>-2.598</td> <td>0.009</td> <td>-0.048</td> <td>-0.007</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Group Var</th>                                                             <td>0.001</td>   <td>0.002</td>     <td></td>      <td></td>       <td></td>       <td></td>   \n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary2.Summary'>\n",
       "\"\"\"\n",
       "                                     Mixed Linear Model Regression Results\n",
       "===============================================================================================================\n",
       "Model:                              MixedLM                   Dependent Variable:                   improvement\n",
       "No. Observations:                   1439                      Method:                               REML       \n",
       "No. Groups:                         72                        Scale:                                0.0097     \n",
       "Min. group size:                    19                        Log-Likelihood:                       1247.8321  \n",
       "Max. group size:                    20                        Converged:                            Yes        \n",
       "Mean group size:                    20.0                                                                       \n",
       "---------------------------------------------------------------------------------------------------------------\n",
       "                                                                     Coef.  Std.Err.   z    P>|z| [0.025 0.975]\n",
       "---------------------------------------------------------------------------------------------------------------\n",
       "Intercept                                                            -0.000    0.006 -0.000 1.000 -0.012  0.012\n",
       "C(condition, Treatment('solo_no_feedback'))[T.dynamic_full_feedback] -0.045    0.011 -4.268 0.000 -0.066 -0.024\n",
       "C(condition, Treatment('solo_no_feedback'))[T.dynamic_no_feedback]   -0.020    0.011 -1.904 0.057 -0.041  0.001\n",
       "C(condition, Treatment('solo_no_feedback'))[T.dynamic_self_feedback] -0.028    0.011 -2.598 0.009 -0.048 -0.007\n",
       "Group Var                                                             0.001    0.002                           \n",
       "===============================================================================================================\n",
       "\n",
       "\"\"\""
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"study 2 overall improvement of the best individual -- revised\")\n",
    "\n",
    "forumla = \"improvement ~ C(condition, Treatment('solo_no_feedback'))\"\n",
    "data = round_data[(round_data.study==2) & (round_data.improvement.notnull()) & (round_data.best_player_revised)]\n",
    "model = smf.mixedlm(forumla, data= data,groups=data['player_id']).fit(method='powell')\n",
    "reduced_error = (data[data.condition == 'dynamic_no_feedback'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic_no_feedback'].independent_error.mean() ) / data[data.condition == 'dynamic_no_feedback'].independent_error.mean()\n",
    "\n",
    "print(\"dynamic_no_feedback reduced error by \", reduced_error*100)\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic_self_feedback'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic_self_feedback'].independent_error.mean() ) / data[data.condition == 'dynamic_self_feedback'].independent_error.mean()\n",
    "\n",
    "print(\"dynamic_self_feedback reduced error by \", reduced_error*100)\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic_full_feedback'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic_full_feedback'].independent_error.mean() ) / data[data.condition == 'dynamic_full_feedback'].independent_error.mean()\n",
    "\n",
    "print(\"dynamic_full_feedback reduced error by \", reduced_error*100)\n",
    "\n",
    "\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "study 2 adapted improvement of the best individual -- revised\n",
      "dynamic_no_feedback reduced error by  -15.81219643820826\n",
      "dynamic_self_feedback reduced error by  -28.13536828135364\n",
      "dynamic_full_feedback reduced error by  -62.31122783979004\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "       <td>Model:</td>       <td>MixedLM</td> <td>Dependent Variable:</td> <td>improvement</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <td>No. Observations:</td>   <td>719</td>         <td>Method:</td>          <td>REML</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "     <td>No. Groups:</td>      <td>72</td>          <td>Scale:</td>          <td>0.0088</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Min. group size:</td>     <td>9</td>      <td>Log-Likelihood:</td>    <td>668.2240</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Max. group size:</td>    <td>10</td>        <td>Converged:</td>          <td>Yes</td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <td>Mean group size:</td>   <td>10.0</td>            <td></td>                <td></td>      \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "                                    <td></td>                                    <th>Coef.</th> <th>Std.Err.</th>    <th>z</th>   <th>P>|z|</th> <th>[0.025</th> <th>0.975]</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>                                                             <td>0.000</td>   <td>0.006</td>   <td>0.000</td> <td>1.000</td> <td>-0.011</td>  <td>0.011</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_no_feedback'))[T.dynamic_full_feedback]</th> <td>-0.063</td>   <td>0.010</td>  <td>-6.632</td> <td>0.000</td> <td>-0.082</td> <td>-0.045</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_no_feedback'))[T.dynamic_no_feedback]</th>   <td>-0.020</td>   <td>0.010</td>  <td>-2.057</td> <td>0.040</td> <td>-0.038</td> <td>-0.001</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>C(condition, Treatment('solo_no_feedback'))[T.dynamic_self_feedback]</th> <td>-0.028</td>   <td>0.010</td>  <td>-2.963</td> <td>0.003</td> <td>-0.047</td> <td>-0.010</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Group Var</th>                                                             <td>0.000</td>   <td>0.002</td>     <td></td>      <td></td>       <td></td>       <td></td>   \n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary2.Summary'>\n",
       "\"\"\"\n",
       "                                     Mixed Linear Model Regression Results\n",
       "===============================================================================================================\n",
       "Model:                              MixedLM                   Dependent Variable:                   improvement\n",
       "No. Observations:                   719                       Method:                               REML       \n",
       "No. Groups:                         72                        Scale:                                0.0088     \n",
       "Min. group size:                    9                         Log-Likelihood:                       668.2240   \n",
       "Max. group size:                    10                        Converged:                            Yes        \n",
       "Mean group size:                    10.0                                                                       \n",
       "---------------------------------------------------------------------------------------------------------------\n",
       "                                                                     Coef.  Std.Err.   z    P>|z| [0.025 0.975]\n",
       "---------------------------------------------------------------------------------------------------------------\n",
       "Intercept                                                             0.000    0.006  0.000 1.000 -0.011  0.011\n",
       "C(condition, Treatment('solo_no_feedback'))[T.dynamic_full_feedback] -0.063    0.010 -6.632 0.000 -0.082 -0.045\n",
       "C(condition, Treatment('solo_no_feedback'))[T.dynamic_no_feedback]   -0.020    0.010 -2.057 0.040 -0.038 -0.001\n",
       "C(condition, Treatment('solo_no_feedback'))[T.dynamic_self_feedback] -0.028    0.010 -2.963 0.003 -0.047 -0.010\n",
       "Group Var                                                             0.000    0.002                           \n",
       "===============================================================================================================\n",
       "\n",
       "\"\"\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"study 2 adapted improvement of the best individual -- revised\")\n",
    "\n",
    "forumla = \"improvement ~ C(condition, Treatment('solo_no_feedback'))\"\n",
    "data = round_data[(round_data.study==2) & (round_data.improvement.notnull()) \n",
    "                  & (round_data.best_player_revised)\n",
    "                 & (round_data.quarter.isin([2,4]))]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['player_id']).fit(method='powell')\n",
    "reduced_error = (data[data.condition == 'dynamic_no_feedback'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic_no_feedback'].independent_error.mean() ) / data[data.condition == 'dynamic_no_feedback'].revised_error.mean()\n",
    "\n",
    "print(\"dynamic_no_feedback reduced error by \", reduced_error*100)\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic_self_feedback'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic_self_feedback'].independent_error.mean() ) / data[data.condition == 'dynamic_self_feedback'].revised_error.mean()\n",
    "\n",
    "print(\"dynamic_self_feedback reduced error by \", reduced_error*100)\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic_full_feedback'].revised_error.mean() - \n",
    "                 data[data.condition == 'dynamic_full_feedback'].independent_error.mean() ) / data[data.condition == 'dynamic_full_feedback'].revised_error.mean()\n",
    "\n",
    "print(\"dynamic_full_feedback reduced error by \", reduced_error*100)\n",
    "\n",
    "\n",
    "model.summary()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
